/*
 * Copyright (C) 2012 by Hao Hou<ghost89413@gmail.com>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>*
 */

//Functions to manipulate IMEs
#ifndef __LOADER_H__
#define __LOADER_H__
#include <X11/Xlib.h>
#include <IMdkit.h>
#include <log.h>
#include <ime.h>
#include <Xi18n.h>
/* Maximum Input Method can be managed by Vine */
#define MAX_IME 64
#include <ic.h>
/* Struct for Input Method Context */
typedef struct {
	/* member IC should awlays following by member data */
	struct _InputContext* IC; //Platform IC
	/* DO NOT ADD ANY DEFINITION HERE */
	char	data[0];	  //Address of Userdefined IC
	/* Memory that belongs to user defined IC, should not be used */
} IMIC;

typedef IMMetaData* (*GetMetaDataProc)(void); //Prototype of IME Entry point

IMMetaData*  GetDefaultIM();		 //Find default IME. if dose not exists , return the first
IMMetaData* NextIM(IMMetaData* imdata);  //Search for next IME
int InitIMEs(); //Load IME specified by config file
int LoadIME(const char* filename,char* param); //Load IME by binary name
void FinalizeIMEs();

/*IME list*/
extern IMMetaData* immeta[MAX_IME];

/* Auxiliary Macro for platform invoke IME procedures */
#define IME_CALL(meta,func,...) (((meta)->imfunction.func != NULL)?((meta)->imfunction.func(__VA_ARGS__)):0)
/*Make a fake IC*/
#define MAKE_FAKE_IC(Name,pIM) IMMetaData** __##Name##_ppIM__ = &pIM;\
			       void* Name = (void*)((char*)&__##Name##_ppIM__ + sizeof(IMIC));
#endif
